var onload_ctr={
		bizCode:"",
		resource:"",
		resType:4,
		domain:"",
		addScriptFile:function(url,handler){
			if(document && document.createElement){
				var new_element=document.createElement("script");
				new_element.setAttribute("type","text/javascript");
				new_element.setAttribute("onload",handler);
				new_element.setAttribute("src",url);
				if(document.getElementsByTagName && document.getElementsByTagName('html') && document.getElementsByTagName('html').item(0)){
					var head=document.getElementsByTagName('html').item(0);
					if(head.appendChild){
						head.appendChild(new_element);
					}
				}
			}
		},
		loadScript:function(arr){
	    	if(arr.length>0){
	    		for(var i=0;i<arr.length;i++){
	    			this.addScriptFile(arr[i][0],arr[i][1]);
	    		}
	    	}
		},
		/*
		 * 嵌入虎瑞的代码
		 *
		 */
		loadHTV:function(name,value){
			var scriptArray=new Array();
			scriptArray.push(["http://125.88.98.37:9000/js/TvChatLog.js","onload_ctr.htvChannelLogUpload(0, '"+(typeof(Authentication)!="undefined"?Authentication.CTCGetConfig('UserID'):"")+"', '"+name+"', '"+value+"')"]);
			scriptArray.push(["http://125.88.98.37:9000/tvPopUp/popUp.js",""]);
			this.loadScript(scriptArray);
		},
		
		htvChannelLogUpload:function(type,userid,title,channelNum){
			if(typeof TvChatLog!="undefined" && typeof TvChatLog.logUpload!="undefined"){
				TvChatLog.logUpload(type,userid,title,channelNum);
			}
		},
		
		playVod:function(id){
			var backUrl=location.href;
			location.href=onload_ctr.domain+"play/vod_play.jsp?foreignId="+id+"&backUrl="+escape(backUrl);
		},
		playProg:function(id){
			var backUrl=location.href;
			location.href=onload_ctr.domain+"play/hd_prog_play.jsp?foreignId="+id+"&backUrl="+escape(backUrl);
		},
		playSeries:function(id){
			var backUrl=location.href;
			location.href=onload_ctr.domain+"play/hd_series_play.jsp?foreignId="+id+"&backUrl="+escape(backUrl);
		},
		playChannel:function(id){
			var backUrl=location.href;
			location.href=onload_ctr.domain+"play/channelAndBack_play.jsp?channelIndex="+id+"&backUrl="+escape(backUrl);
		},
		keypressEvent:function(keycode){
			var key_code=parseInt(keycode);
			var event=new Object();
			event.target=document.getElementsByTagName("body")[0];
			event.keyCode=key_code;
			if(typeof(epgPage)!="undefined"){
				epgPage.keypress(event);
			}
		},

		//公用回调函数
		msgPusherHandler:function(message){
			var obj=null;
			if(typeof(message)!="object"){
				obj=JSON.parse(message);
			}else{
				obj=message;
			}
			if(typeof(obj.body)!="undefined" && typeof(obj.body.type)!="undefined" && typeof(obj.body.content)!="undefined"){
				var type=obj.body.type;
				var content=obj.body.content;
				switch(type){
					case "playvod":
						onload_ctr.playVod(content);
						break;
					case "playprog":
						onload_ctr.playProg(content);
						break;
					case "playseries":
						onload_ctr.playSeries(content);
						break;
					case "playchannel":
						onload_ctr.playChannel(content);
						break;
					case "bind":
						{
							if(typeof(wxds_refresh)=="function"){
								wxds_refresh(type,content);
							}
						}
						break;
					case "unbind":
						{
							if(typeof(wxds_refresh)=="function"){
								wxds_refresh(type,content);
							}
						}
						break;
					case "keypress":
						onload_ctr.keypressEvent(content);
						break;
					default:break;
				}
			}
		},

		//虎瑞回调函数
		msgPusherHandler_hr:function(dispatcher,message){
			var msgid=null;
			var msgbody=null; 
			var obj=null;
			if(typeof(message)!="object"){
				obj=JSON.parse(message);
			}else{
				obj=message;
			}
			try{
				if(typeof(obj.id)!="undefined"){
					msgid=obj.id;
				}
			}catch(e){}
			try{
				if(typeof(obj.body)!="undefined"){
					msgbody=obj.body;
				}
			}catch(e){}
			try{
				if(typeof(HRTV)!="undefined" && typeof(HRTV.messageHandler)=="function"){
					HRTV.messageHandler(msgid,msgbody,dispatcher);
				}
			}catch(e){}
			
		},
		/*
		 * 初始化消息通道
		 * resource:来源，厂商EPG首页时为home，频道播放页面频道号，节目播放页为节目的外部编码，看吧为展示栏目CODE
		 * type:类型，目前需要针对channel进行识别
		 * name:名称，当是频道时，填频道的名称
		 * 
		 */
		initMsgPusher:function(bizcode,resource,epgDomain,type,name){
			this.bizCode=bizcode;
			this.resource=resource;
			this.domain=epgDomain;
			//如果是频道播放页面，需要先加载虎瑞的JS
			if(typeof(type)!="undefined"){
				if(type=="channel"){
					this.loadHTV(name,resource);
					this.resType=1;
				}
			}
			if(typeof(msgPusher)=="undefined"){
				msgPusher=new MsgPusher();
			}
			var mediaPlayer=null;
			if(typeof(mp)!="undefined"){
				mediaPlayer=mp;
			}
			msgPusher.setOptions({
				epg:(typeof(Authentication)=="undefined") ? "" : Authentication.CTCGetConfig("templateName"),
				stbType:(typeof(Authentication)=="undefined") ? "" : Authentication.CTCGetConfig("STBType"),
				userId: (typeof(Authentication)=="undefined") ? "" : Authentication.CTCGetConfig("UserID"),
				resources: resource,
				restype: this.resType,
				mediaPlayer: mediaPlayer,
				hosts: ["14.29.2.19","14.29.2.20"],
				//用于验证请求是否来至EPG
				epgSession: /JSESSIONID=(.*?)(;|$)/.exec(document.cookie)[ 1 ]
				//epgSession:"09C6E2FD20AE66DDA864C40F2E8F2150"
			});
			//粤TV
			msgPusher.registerHandler(this.msgPusherHandler,100);
			msgPusher.registerHandler(this.msgPusherHandler,200);
			msgPusher.registerHandler(this.msgPusherHandler,300);
			msgPusher.registerHandler(this.msgPusherHandler,400);
			msgPusher.registerHandler(this.msgPusherHandler,600);
			//添加虎瑞回调方法,只有频道播放页，才需要调
			if(typeof(type)!="undefined"){
				if(type=="channel"){
					new MsgDispatcher(msgPusher,200,this.msgPusherHandler_hr);
				}
			}
			msgPusher.connect();
		}
}